/****************************************************
          File Name:15-3.cpp
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Sun Jan 11 18:40:26 2015
*****************************************************/

#include "15-3.h"
#include <cmath>

double hmean(double a, double b)
{
    if(a == -b)
        throw hmeanexcp(a,b);
    return 2.0 * a * b / (a + b);
}

double gmean(double a, double b)
{
    if(a < 0 || b < 0)
        throw gmeanexcp(a,b);
    return std::sqrt(a*b);
}

int main()
{
    using std::cout;
    using std::cin;
    using std::endl;

    double x , y, z;

    cout << "Enter two numbers: ";
    while(cin >> x >> y)
    {
        try
        {
            z = hmean(x,y);
            cout << "Harmonic mean of " << x << " and " << y
                << " is " << gmean(x,y) << endl;
            cout << "Enter next set of numbers <q to quit>: ";
        }
        catch (hmeanexcp & bg)
        {
            bg.msg();
            cout << bg.what();
            cout << "Sorry, you don;t get to play any more.\n";
            break;
        }
        catch (gmeanexcp & bh)
        {
            bh.msg();
            cout << bh.what();
            cout << "Sorry, you don;t get to play any more.\n";
            break;
        }
    }

    cout << "Bye!\n";
    return 0;
}
